package com.bigkoo.pickerviewdemo.dayweekhalfhour;

import com.bigkoo.pickerview.adapter.WheelAdapter;
import java.util.ArrayList;
import java.util.List;

/**
 * 创建时间：2016年08月11日15:32 <br>
 * 作者：fuchaoyang <br>
 * 描述：
 */
public class HalfHourNumericWheelAdapter implements WheelAdapter<String> {
  private static final String POSTFIX_HALF_HOUR = ":30";

  private List<String> mTimeList;

  /**
   *
   * @param minValue
   * @param startHalf
   * @param maxValue
   * @param endHalf
   */
  public HalfHourNumericWheelAdapter(int minValue, boolean startHalf, int maxValue,
      boolean endHalf) {
    mTimeList = initDate(minValue, startHalf, maxValue, endHalf);
  }

  private ArrayList<String> initDate(int minValue, boolean startHalf, int maxValue,
      boolean endHalf) {
    ArrayList<String> timelist = new ArrayList<String>();
    String starttime;
    if (startHalf) {
      starttime = minValue + ":30";
      timelist.add(starttime);
      minValue++;
    }

    for (int i = minValue; i <= maxValue; i++) {
      String timehalf, timetick;
      timetick = i + ":00";
      timelist.add(timetick);
      if ((i == maxValue && endHalf) || i < maxValue) {
        timehalf = i + ":30";
        timelist.add(timehalf);
      }
    }
    return timelist;
  }

  @Override public int getItemsCount() {
    return mTimeList.size();
  }

  @Override public String getItem(int index) {
    return mTimeList.get(index);
  }

  @Override public int indexOf(String o) {
    return mTimeList.indexOf(o);
  }
}
